#ifndef GAME_H_INCLUDED
#define GAME_H_INCLUDED

#include "Singleton.h"
#include "GameState.h"
#include "GameObject.h"
#include "CustomCursor.h"


//#include "btBulletDynamicsCommon.h"
class btCollisionShape;
class btDefaultCollisionConfiguration;
class btCollisionDispatcher; 
class btBroadphaseInterface;
class btSequentialImpulseConstraintSolver;
class btDiscreteDynamicsWorld;
class btMotionState;
class GameObject;

class Game : public Uncopyable
{
private:
	Game();
	friend class Singleton<Game>;
public:
	void Start();
	
	void Draw();
	void Update();
	void SetGameState(GameState* theGameState);
	
	GameObject* GetGameObject(int id);

	void DrawGameObjects();
	void UpdateGameObjects();
	void AddGameObject(int id, GameObject* g);
	void DeleteGameObjects();

	GameObjectsMap* GetGameObjects() { return &m_objects; }
	int GetFrameNumber();



	//Bullet Functions
	void BTSetDefaultCollisionConfig(btDefaultCollisionConfiguration* config);
	void BTSetCollisionDispatcher(btCollisionDispatcher* dispatch);
	void BTSetBroadPhase(btBroadphaseInterface* broad);
	void BTSetConstraintSolver(btSequentialImpulseConstraintSolver* solver);
	bool BTCreateDynamicsWorld();
	void BTCheckPairs();
	void BTCollisionsOn(bool coll = true);
	void BTReset();
	
	btDiscreteDynamicsWorld* GetDynWorld();
	btBroadphaseInterface* GetBroadInterface();
	void BTSetMotionState(btMotionState* state);
	void AddCollisionShape(btCollisionShape* collShape);

	~Game();

private:
	GameState* mp_State;
	GameObjectsMap m_objects;
	GameObjectsMap::iterator m_it;
	unsigned int m_frameNumber;
	unsigned int m_numManifolds;
	unsigned int m_numContacts;


	

	//Bullet collision variables
	bool m_collisionOn;
	Vec3f m_gravity;

	btAlignedObjectArray<btCollisionShape*>* mp_collisionShapes;
	btDefaultCollisionConfiguration* mp_collisionConfiguration;
	btCollisionDispatcher* mp_dispatcher; 
	btBroadphaseInterface* mp_broadphase;
	btSequentialImpulseConstraintSolver* mp_constraintSolver;
	btDiscreteDynamicsWorld* mp_dynamicsWorld;
	btPersistentManifold* mp_manifold;
	btCollisionObject* mp_obA;
	btCollisionObject* mp_obB;

	//Custom Cursor design
	CustomCursor m_cursor;
	
};

typedef Singleton<Game> TheGame;

#endif